package com.demo.validation;

import cn.hutool.core.lang.Validator;
import com.demo.annotation.ValidEmail;
import org.apache.commons.lang3.StringUtils;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * @author wangfengchen
 */
public class EmailValidator implements ConstraintValidator<ValidEmail, String> {

  @Override
  public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {
    if (StringUtils.isNotBlank(s)) {
      return Validator.isEmail(s);
    }
    return true;
  }
}
